<?php
/**
 * TotemToo default controller
 * 
 * @package    Joomla.Tutorials
 * @subpackage Components
 * @license		GNU/GPL
 */
defined( '_JEXEC' ) or die('Restricted access');

jimport('joomla.application.component.controller');

/**
 * TotemToo Component Controller
 * Chiamando la classe controller TotemTooController le views e i modelli devono avere sempre prefisso TotemToo
 * Controller che visualizza tutte le righe degli Immobili
 *
 * @package    Joomla.Tutorials
 * @subpackage Components
 */

class TotemTooController extends JController
{

	function __construct()
	{
	    parent::__construct();

	    // Identifico Add con Edit (task)
	    $this->registerTask( 'add'  ,  'edit' );
	    $this->registerTask( 'submit'  ,  'save' );
	}

	/**
	 * Method to upload the file
	 *
	 * @access	public
	 */
	function upload() {
	/*	$model = $this->getModel('totemtoo');
		$view =& $this->getView('edit','html');
		$view->setModel($model);
		$view->display(); */
	}

	/**
	 * Method to display the view
	 *
	 * @access	public
	 */
	function edit() {
		$model = $this->getModel('totemtoo');
		$view =& $this->getView('edit','html');
		$view->setModel($model);
		$view->display();
	}

	/**
	 * Method to submit a record
	 *
	 * @access	public
	 */
	function save() {
		$model = $this->getModel('totemtoo');
		if ($model->store()) {
			$msg = JText::_( 'Immobile Salvato!' );
		} else {
			$msg = JText::_( 'Errore Nel Salvataggio Dell\'immobile! Controlla i Dati Inseriti!' );
		}

		// Check the table in so it can be edited.... we are done with it anyway
		$link = 'index.php?option=com_totemtoo';
		$this->setRedirect($link, $msg);
	}	

	function publish() {
		global $option;
		$cid = JRequest::getVar('cid', array(0),'', 'array');
		$this->addModelPath(JPATH_COMPONENT_SITE . DS . 'models');
		$model = $this->getModel('totemtoo');
		$table =& $model->getTable('totemtoo');
		$table->publish($cid);
		$msg = JText::_('Immobile/i pubblicato/i');
		$this->setRedirect('index.php?option='.$option, $msg);
	}

	function unpublish() {
		global $option;
		$cid = JRequest::getVar('cid', array(0),'', 'array');
		$this->addModelPath(JPATH_COMPONENT_SITE . DS . 'models');
		$model = $this->getModel('totemtoo');
		$table =& $model->getTable('totemtoo');
		$table->publish($cid, 0);
		$msg = JText::_('Immobile/i non pubblicato/i');
		$this->setRedirect('index.php?option='.$option, $msg);
	}

	
	function cancel() {
		$msg = JText::_( 'Operazione annullata' );
		$this->setRedirect( 'index.php?option=com_totemtoo', $msg );
	}
	
	function remove() {
		$model = $this->getModel('totemtoo');
		$view =& $this->getView('totemtoo','html');
		$view->setModel($model);
		$view->assignRef('data', $data);
		if(!$model->delete()) {
			$msg = JText::_('Errore: Non sono stati cancellati immobili');
		} else {
			$msg = JText::_('Record cancellato/i');
		}
		$this->setRedirect( 'index.php?option=com_totemtoo', $msg );
	}

}
?>
